package com.zhtools.excel.handler;

import com.zhtools.excel.TypeHandler;

import java.math.BigDecimal;
import java.util.HashMap;
import java.util.Map;

public final class TypeHandlerManager {
    private static Map<Class<?>, TypeHandler<?>> BASICTYPEHANDLERS = new HashMap<>();

    static {
        BASICTYPEHANDLERS.put(Long.TYPE, new LongTypeHandler());
        BASICTYPEHANDLERS.put(Long.class, new LongTypeHandler());
        BASICTYPEHANDLERS.put(Integer.TYPE, new IntegerTypeHandler());
        BASICTYPEHANDLERS.put(Integer.class, new IntegerTypeHandler());
        BASICTYPEHANDLERS.put(Boolean.TYPE, new BooleanTypeHandler());
        BASICTYPEHANDLERS.put(Boolean.class, new BooleanTypeHandler());
        BASICTYPEHANDLERS.put(BigDecimal.class, new BigDecimalTypeHandler());
        BASICTYPEHANDLERS.put(String.class, new StringTypeHandler());
    }

    public static <T> TypeHandler<T> getTypeHandler(Class<T> clazz) {
        boolean contains = BASICTYPEHANDLERS.containsKey(clazz);
        if (contains) {
            return (TypeHandler<T>) BASICTYPEHANDLERS.get(clazz);
        }
        return null;
    }
}
